package com.villaday.idf.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.OnAdapterCallbackListener;
import com.villaday.idf.model.Member_favor_listEntity;
import com.villaday.idf.model.RecommendEntity;
import com.villaday.idf.model.RefreshtokenEntity;
import com.villaday.idf.util.PhoneUtil;
import com.villaday.idf.util.SharedPreferencesUtil;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * 首页动态列表
 */

public class FavoriteListFindAdapter<T> extends AbsRecyclerViewAdapter<Member_favor_listEntity.BodyEntity.ListEntity> {
    private OnAdapterCallbackListener onAdapterCallbackListener;
    private View.OnClickListener onClickListener;
    private final String roleType;

    public FavoriteListFindAdapter(Context context, OnAdapterCallbackListener onAdapterCallbackListener, View.OnClickListener onClickListener) {
        super(context, R.layout.item_favorite, R.layout.item_page_loading,
                R.layout.item_page_bottom, R.layout.item_favorite);
        this.onAdapterCallbackListener = onAdapterCallbackListener;
        this.onClickListener = onClickListener;
        RefreshtokenEntity.BodyBean roleInfo =
                SharedPreferencesUtil.getRoleInfo(context);
        roleType = roleInfo.getMember().getType();

    }

    @Override
    public int getItemType(Member_favor_listEntity.BodyEntity.ListEntity d) {
        if (d.getModelType() == 7) {
            return 3;
        } else {
            return d.getMyType();
        }

    }

    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, Member_favor_listEntity.BodyEntity.ListEntity d, int position) {
        switch (d.getMyType()) {

            case 0: {
                if (d.getModelType() == 7) {//酒店
                    holder.bindSimpleDraweeView(R.id.sdv, d.getImageURL() + "")
                            .bindTextView(R.id.tv_title, d.isHasHouse() ? d.getHouse().getName() : d.getName());
                    if (d.getAround() == null) {
                        holder.bindTextView(R.id.tv_des, d.getLevelName() + (TextUtils.isEmpty(d.getArea()) ? "" : " | " + d.getArea()));

                    } else {
                        holder.bindTextViewWithHtml(R.id.tv_des, d.getLevelName() + (TextUtils.isEmpty(d.getArea()) ? "" : " | " + d.getArea()) + (" | " + "距" + d.getAround().getAroundName() + String.format(context.getResources().getString(R.string.jdtext), d.getAround().getAroundDist() + "") + "公里"));

                    }

                    holder.setViewVisible(R.id.tv_tuiguang, "0".equals(roleType) ? View.GONE : (d.isOffline() ? View.GONE : View.VISIBLE))
                            .setViewVisible(R.id.tv_xiajia, d.isOffline() ? View.VISIBLE : View.GONE)
                            .setViewVisible(R.id.tv_temai, d.getModelType() == 52 ? View.VISIBLE : View.GONE)
                            .setViewVisible(R.id.ll_Zhuan, "0".equals(roleType) ? View.INVISIBLE : View.VISIBLE)
                            .setViewVisible(R.id.tv_qi1,  View.VISIBLE)
                            .setViewVisible(R.id.tv_qi,  View.VISIBLE)


                            .setClickListenerAndTag(R.id.tv_tuiguang, onClickListener, position)
                            .bindTextViewWithHtml(R.id.tv_Zhuan, "赚" + "&yen;" + d.getBrokerAgeAmountValue())

                            .bindTextViewWithHtml(R.id.tv_price, "&yen;" + (d.getCurrentPrice() == 0 ? "0.00" : PhoneUtil.handleBalance(d.getCurrentPrice() / 100.0 + "", 0)));

                    PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_price), true);
                    PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_qi), false);
                    PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_Zhuan), true);
                    PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_qi1), true);

                } else if (d.getModelType() ==52){//特卖
                    holder.bindSimpleDraweeView(R.id.sdv, d.getImageURL() + "")
                            .bindTextView(R.id.tv_title, d.isHasHouse() ? d.getHouse().getName() : d.getName())
                            .bindTextView(R.id.tv_des, d.getHouse().getRoomNum() + "室" + d.getHouse().getHallNum() + "厅" + d.getHouse().getBedNum() + "床" + "  |  " + d.getHouse().getAcreage() + "㎡" + "  |  " + (d.getHouse().getHouseType() == 3 ? "可玩" : "宜住") + d.getHouse().getPeopleNum() + "人")
                            .setViewVisible(R.id.tv_tuiguang, "0".equals(roleType) ? View.GONE : (d.isOffline() ? View.GONE : View.VISIBLE))
                            .setViewVisible(R.id.tv_xiajia, d.isOffline() ? View.VISIBLE : View.GONE)
                            .setViewVisible(R.id.tv_temai, d.getModelType() == 52 ? View.VISIBLE : View.GONE)
                            .setViewVisible(R.id.ll_Zhuan, "0".equals(roleType) ? View.INVISIBLE : View.VISIBLE)
                            .setViewVisible(R.id.tv_qi1,  View.GONE)
                            .setViewVisible(R.id.tv_qi,  View.GONE)

                            .setClickListenerAndTag(R.id.tv_tuiguang, onClickListener, position)
                            .bindTextViewWithHtml(R.id.tv_Zhuan, "赚" + "&yen;" + d.getBrokerAgeAmountValue())

                            .bindTextViewWithHtml(R.id.tv_price, "&yen;" + (d.getCurrentPrice() == 0 ? "0.00" : PhoneUtil.handleBalance(d.getCurrentPrice() / 100.0 + "", 0)))
                            .setViewVisible(R.id.tv_des, d.isHasHouse() ? View.VISIBLE : View.INVISIBLE);

                    PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_price), true);
                    PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_qi), false);
                    PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_Zhuan), true);
                    PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_qi1), true);
                }else {//普通
                    holder.bindSimpleDraweeView(R.id.sdv, d.getImageURL() + "")
                            .bindTextView(R.id.tv_title, d.isHasHouse() ? d.getHouse().getName() : d.getName())
                            .bindTextView(R.id.tv_des, d.getHouse().getRoomNum() + "室" + d.getHouse().getHallNum() + "厅" + d.getHouse().getBedNum() + "床" + "  |  " + d.getHouse().getAcreage() + "㎡" + "  |  " + (d.getHouse().getHouseType() == 3 ? "可玩" : "宜住") + d.getHouse().getPeopleNum() + "人")
                            .setViewVisible(R.id.tv_tuiguang, "0".equals(roleType) ? View.GONE : (d.isOffline() ? View.GONE : View.VISIBLE))
                            .setViewVisible(R.id.tv_xiajia, d.isOffline() ? View.VISIBLE : View.GONE)
                            .setViewVisible(R.id.tv_temai, d.getModelType() == 52 ? View.VISIBLE : View.GONE)
                            .setViewVisible(R.id.ll_Zhuan, "0".equals(roleType) ? View.INVISIBLE : View.VISIBLE)
                             .setViewVisible(R.id.tv_qi1,  View.VISIBLE)
                            .setViewVisible(R.id.tv_qi,  View.VISIBLE)

                            .setClickListenerAndTag(R.id.tv_tuiguang, onClickListener, position)
                            .bindTextViewWithHtml(R.id.tv_Zhuan, "赚" + "&yen;" + d.getBrokerAgeAmountValue())

                            .bindTextViewWithHtml(R.id.tv_price, "&yen;" + (d.getCurrentPrice() == 0 ? "0.00" : PhoneUtil.handleBalance(d.getCurrentPrice() / 100.0 + "", 0)))
                            .setViewVisible(R.id.tv_des, d.isHasHouse() ? View.VISIBLE : View.INVISIBLE);

                    PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_price), true);
                    PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_qi), false);
                    PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_Zhuan), true);
                    PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_qi1), true);
                }


                break;
            }
            case 1: {
                onAdapterCallbackListener.onCallback();
            }
            break;


        }
    }
}
